package com.own.business.log.login.persistence.entity.vo;

import com.alibaba.fastjson2.JSON;
import com.own.business.log.login.persistence.entity.po.LogLoginElasticPo;
import com.own.component.elastic.entity.BaseElasticVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * LogLoginElasticVo
 *
 * @author chenxueli
 * @date 2023-12-20 10:08:25
 */
@Schema(title = "登录日志持久化" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class LogLoginElasticVo extends BaseElasticVo<LogLoginElasticPo> implements Serializable {

    @Schema(title = "登录账号")
    private String loginAccount;

    @Schema(title = "登录类型")
    private String loginType;

    @Schema(title = "登录编码")
    private String loginCode;

    @Schema(title = "用户id")
    private Long userId;

    @Schema(title = "用户名")
    private String userName;

    @Schema(title = "ip地址")
    private String ip;

    @Schema(title = "客户端")
    private String client;

    @Schema(title = "token")
    private String token;

    @Schema(title = "操作内容")
    private String extra;

    @Schema(title = "登录状态 1=成功 2=失败")
    private Integer status;

    @Schema(title = "链路id")
    private String traceId;

    @Schema(title = "请求头")
    private String headerParams;

    @Override
    public void of(@NonNull LogLoginElasticPo entity) {
        super.of(entity);
        this.loginAccount = entity.getLoginAccount();
        this.loginType = entity.getLoginType();
        this.loginCode = entity.getLoginCode();
        this.userId = entity.getFkUserId();
        this.userName = entity.getUserName();
        this.ip = entity.getIp();
        this.client = entity.getClient();
        this.token = entity.getToken();
        this.extra = JSON.toJSONString(entity.getExtra());
        this.status = entity.getStatus();
        this.traceId = entity.getTraceId();
        this.headerParams = JSON.toJSONString(entity.getHeaderParams());
    }

}
